using System;
using System.Data;
using System.Data.SqlClient;
using Framework.Library;
using FrameWork.Module.Organization;
using FrameWork.Module.Organization.Library.DataAccess;
using Framework.Library.Helper;
using Framework.Library.Utilities;


namespace Framework.Module.Organization.Library.Providers
{
	public class SqlDataProvider : DataAccessProvider
	{
        private string ConnectionString;
        
        public SqlDataProvider(string connStr)
        {
            this.ConnectionString = connStr;
        }

        public override DataTable GetPortalsByLang(string _lang)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Portal_Portals_GetAllByLang", _lang);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override int AddCategory(OrganizationCategoryInfo category)
        {
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "Organization_Category_Insert", category.Category, AppEnv.GetLanguage());
        }

        public override DataTable GetCategory()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Organization_Category_GetAll");
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override OrganizationCategoryInfo GetCategory(int _categoryId)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Organization_Category_GetInfo", _categoryId);
            OrganizationCategoryInfo info = (OrganizationCategoryInfo)ObjectHelper.CreateObject(typeof(OrganizationCategoryInfo), dr);
            return info;
        }

        public override void DeleteCategory(int categoryId)
        {
            SqlHelper.ExecuteNonQuery(this.ConnectionString, "Organization_Category_Delete", categoryId);
        }

        public override void UpdateContent(OrganizationCategoryInfo category)
        {
            SqlHelper.ExecuteNonQuery(this.ConnectionString, "CMS_Contents_Update", category.Category, AppEnv.GetLanguage());
        }
     }
}
